<template>
	<view>
		<view class="menuBox">
			<view class="menuItem"   @click="goto('index')">
				<image :src="seleRouter == 'pages/index/index'?'../../static/menu/ai-2.png':'../../static/menu/ai-1.png'" mode="widthFix"></image>
				<text :class="seleRouter == 'pages/index/index'?'sele':''">爱美图</text>
			</view>
		<!-- 	<view class="menuItem"   @click="goto('coupon')" >
				<image :src="seleRouter == 'pages/index/coupon'?'../../static/menu/icon-03.png':'../../static/menu/icon-07.png'" mode="widthFix"></image>
				<text :class="seleRouter == 'pages/index/coupon'?'sele':''">领券</text>
			</view> -->
			<view class="menuItem"   @click="goto('user')" >
				<image :src="seleRouter == 'pages/index/user'?'../../static/menu/me-2.png':'../../static/menu/me-1.png'" mode="widthFix"></image>
				<text :class="seleRouter == 'pages/index/user'?'sele':''">我的</text>
			</view>
			<!-- <view class="menuItem"   @click="goto('paint')" >
				<image :src="seleRouter == 'pages/index/paint'?'../../static/menu/icon-10.png':'../../static/menu/icon-09.png'" mode="widthFix"></image>
				<text :class="seleRouter == 'pages/index/paint'?'sele':''">绘画</text>
			</view>
			<view class="menuItem"   @click="goto('order')">
				<image :src="seleRouter == 'pages/index/order'?'../../static/menu/icon-02.png':'../../static/menu/icon-06.png'" mode="widthFix"></image>
				<text :class="seleRouter == 'pages/index/order'?'sele':''">订单 </text>
			</view>-->
			
		</view>
	</view>
</template>

<script>
	import {
		parseUserData,
		setInfo,
		quit,
	} from '../../hook/auth.js'
	export default {
		name:"Menu",
		data() {
			return {
				seleRouter:"pages/index/index",
				loginFlag:false//登录标志，true表示已登录
			}
		},
		methods: {
			 goto(url){
				 if(url!="index"){
					 this.getLocalLoginInfo()
					 if(!this.loginFlag){
					 	//没有登录信息，调用抖音登录
						 uni.navigateTo({
						 	url: "loginFun"
						 });
						 return false
					 }else{
						 uni.redirectTo({
						 	url: "me"
						 });
					 }
				 }
				 
					uni.redirectTo({
						url: url
					});
				
			},
			//获取本地登录信息
			getLocalLoginInfo() {
				if(!parseUserData() || !parseUserData().avatarUrl){
					this.loginFlag = false
					quit()
				}else{
					this.loginFlag = true
				}
			},
		},
		mounted() {
			const  pages = getCurrentPages();
			const page = pages[pages.length - 1];
			this.seleRouter = page.route
			this.getLocalLoginInfo()
		}
	}
</script>

<style>
	.menuItem .sele{
		color: rgba(255, 255, 255, 1);
	}
	.menuItem text{
		display: block;
		margin-top: -2px;
	}
	.menuItem image{
		width: 30px;
		margin-top: 4px;
	}
	.menuItem{
		flex:1;
		text-align: center;
		
		font-size: 16px;
		font-weight: 400;
		letter-spacing: 0px;
		color: rgba(166, 166, 166, 1);
	}
	.menuBox{
		position: fixed;
		bottom: 0;
		display: flex;
		width: 100%;
		height: 70px;
		z-index: 999;
		background-color: #1C1C1C;
	}
</style>
